load(file="/Users/raphaellemomal/these/Data_Oak_remmoa/REMMOA/output/20180620_PLN_REMMOANC.RData")
colnames(X)[7:8]<-c("Xcart","Ycart")
null_index=which(rowSums(Y)==0)
Y=as.matrix(Y[-null_index,])
X=data.frame(X[-null_index,])
N=as.matrix(N[-null_index,])
Y_corr=as.matrix(Y/N)
Y_corr[!is.finite(Y_corr)]<-0
mat_effort=outer(X$Effort,rep(1,32))
X[,c(6:10,14:20)]<-apply(X[,c(6:10,14:20)], 2, function(x) as.numeric(x))
repart_species<-function(species){
species=enquo(species)
as_tibble(Y/mat_effort) %>%
dplyr::select(!!species) %>% cbind(Canyon=X$DistCanyon, Cote=X$DistCot) %>%
filter(!!species!=0) %>%
gather(dist, value, -!!species) %>%
ggplot(aes(value,!!species , color=dist))+labs(x="Distance")+
geom_point()+facet_grid(.~dist, scales = "free")+scale_color_brewer(palette="Set1")+guides(color=FALSE)
}
repart_species(SMADEL)
as_tibble(Y/mat_effort) %>% cbind(Canyon=X$DistCanyon, Cote=X$DistCot) %>%
gather(key, value,-Canyon,-Cote) %>%
filter(value!=0) %>% gather(type,dist, -key, -value ) %>%
ggplot(aes(dist,value , color=type))+labs(x="Distance")+
geom_point()+facet_grid(key~type, scales = "free")+scale_color_brewer(palette="Set1")+guides(color=FALSE)
matrice d’offsets sample_specific à partir de la covariable “Effort”
GRETER, BROTER, BROPET, ANOSPP en palliers
library(PLNmodels)
# à faire sur les résiuds de PLN dans l'epace latent
model=PLN(Y~X$Depth+offset(log(mat_effort)))
##
## Initialization...
## Adjusting PLN model with full covariance model
## Computing (pseudo) R2
## Warning: glm.fit: fitted rates numerically 0 occurred
##
## DONE!
M=model$var_par$M
S=model$var_par$S # variance ou sd ?
x=15
indexes=which(Y[,x]!=0)
distdata=X[indexes,c("latitude","longitude")] # ! lati puis longi
Mfiltre<-M[indexes,]
Sfiltre<-M[indexes,]
dists<-compute_distance(distdata)
#Zi=mvrnorm(n=1,mu=Mfiltre[1,],Sigma=diag(c(Sfiltre[1,]%*%Sfiltre[1,]), 10, 10))
# diffs<-compute_diffs(spInd=x,(N)[indexes,]) #bropet 26 pour remmoa
diffs<-compute_diffs(spInd=x,Y[indexes,],Mfiltre,Sfiltre)
scatter_vgm(dists, diffs, colnames(Y)[x])
x=x+1
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/raphaellemomal/these/Data_Oak_remmoa/REMMOA/shape/SecteurNC_UTM58.shp", layer: "SecteurNC_UTM58"
## with 1 features
## It has 5 fields
## Regions defined for each Polygons
map_species(DASSPP,N)
map_species(DASSPP,Y, count=TRUE)
map_species(FOUS,Y, count=TRUE, vecBounds=c(7.76e6,max(X$Ycart),2e5, 6e5))
map_species(FOUS,Y, count=TRUE, vecBounds=c(min(X$Ycart),7.5e6,4e5, 9e5))
# map_species(DASSPP,M, count=TRUE)
# colnames(S) = colnames(Y)
# map_species(DASSPP,S, count=TRUE)
N=as_tibble(N) %>% mutate(sum=rowSums(.))
W=ifelse(N[,-33]>0,1,0)
W=as_tibble(W) %>% mutate(sum=rowSums(.))
# map_species(sum,N )
# map_species(sum,Y, count=TRUE)
map_species(sum,W,low="slateblue1",high="orange", filter=1)